WeightedAverage (fld, fld), WeightedAverage (fld, fld, condFld), WeightedAverage (fld, fld, condFld, cond)
Basic and Crystal syntax.
Arguments
- fld is any valid numeric database or formula field that can be evaluated by the function.
- condFld is a field used to group the values in fld by.
- cond is a String indicating the type of grouping for condFld. You only specify this argument when condFld is a Date, Time, DateTime or Boolean field. For more information on the valid strings for this argument, see Conditions for summary functions.
Returns
Fractional Number
Action
Enables you to calculate the weighted average of the specified fields. When you calculate a weighted average, you are actually calculating the average of one field and then using the values in another field to "weigh" the contribution of each value in the first field to the average. In a normal average, all the weights are equal to 1.
For example:
- You can calculate the weighted average of two fields. For information about this kind of summary, see SummaryFunction (fld).
- You can calculate the weighted average of two fields, for all the values within a group (for example, sales grouped by the state that they come from). For information on this kind of summary, see SummaryFunction (fld, condFld).
- You can calculate the weighted average of two fields, for all the values within a group in which grouping is controlled by changes in a date or Boolean field (for example, sales grouped by the month in which they were made). For information on this kind of summary, see SummaryFunction (fld, condFld, cond).
Examples
The following example is applicable to both Basic and Crystal syntax:
WeightedAverage({table.FIELD1}, {table.FIELD2})
Returns 3.5, where the two fields have four values each. Field1 has values of 3, 2, 5, and 1. Field2 has values of 0, 1, 1, and 0. WeightedAverage calculates as follows: (3*0 + 2*1 + 5*1 + 1*0)/sum{table.FIELD2}
) = 3.5.
Note: Using this function in a formula forces the formula to be evaluated at print time. For more information on evaluation time considerations, see the Evaluation Time functions.